跳到主要内容

240 搜索二维矩阵 II

https://leetcode.cn/leetbook/read/top-interview-questions-medium/xvc64r/

cost: NaN

class Solution {
public:
bool searchMatrix(vector<vector<int>>& matrix, int target) {
int x = 0, y = matrix[0].size() - 1;
while (x < matrix.size() && y >= 0) {
if (matrix[x][y] == target) {
return true;
}
if (matrix[x][y] > target) {
y--;
continue;
}
if (matrix[x][y] < target) {
x++;
continue;
}
}
return false;
}
};